package com.training.java.core.collections.car.post15;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.training.java.core.collections.car.pre15.*;



//This class is creating 4 instances of car with one car having null values.
//Created an array_list of cars.
//Added car instances into that list with one duplicate car.
//List has been iterated using iterator
//printed the value of Cars using while loop and for loop.


public class CarCollectionDemo {

	public static void main(String[] args) {
		Car car1= new Car("Toyota","Corolla",2010);
        Car car2= new Car("Honda","CRV",2012);
        Car car3 = new Car("Ford","focus",2007);
        Car car4 = new Car();  
       
        car1.setPrice(17999.99);
		car2.setPrice(24999.99);
		car3.setPrice(19999.99);

       
        List<Car> listOfCars = new ArrayList<Car>();
       
        //Duplicate cars are allowed in list
       
        listOfCars.add(car1);
        listOfCars.add(car1);
        listOfCars.add(car2);
        listOfCars.add(car3);
        listOfCars.add(car4);
       
       
        Iterator<Car> ite = listOfCars.iterator();
         System.out.println("Info of Cars using while loop.\n");
        while(ite.hasNext())
        {
                 Car car =ite.next();
               
           System.out.println("Make:  " + car.getMake());
           System.out.println("Model: " + car.getModel());
           System.out.println("Year: " +  car.getYear());
           System.out.println("Price: " +  car.getPrice());
           System.out.println("************");
               
        }
        System.out.println("\nInfo of Cars using for each loop.");
       
        for(Car aCar : listOfCars)
        {
               
           System.out.println("Make:  " + aCar.getMake());
           System.out.println("Model: " + aCar.getModel());
           System.out.println("Year: " +  aCar.getYear());
           System.out.println("Price: " +  aCar.getPrice());
           System.out.println("************");
        }
        

	}

}
